import { ref } from 'vue';
import { createGlobalState } from '@vueuse/core';
import { listToEnum, listToOption } from '@/utils/utils';
import { getDictType } from '@/api/monitor';

export const systemStore = createGlobalState(() => {
  // 字典-通知类型
  const noticeOptions = ref<Global.Option[]>([]);
  const noticeEnum = ref<Record<string, any>>({});
  const getNoticeTypeDict = () => {
    getDictType('sys_notice_type').then((res: any) => {
      noticeOptions.value = listToOption(
        res.data as any[],
        'dictLabel',
        'dictValue',
      );
      noticeEnum.value = listToEnum(
        res.data as any[],
        'dictValue',
        'dictLabel',
      );
    });
  };

  const refreshStore = {
    notice() {
      getNoticeTypeDict();
    },
  };
  return {
    refreshStore,
    noticeOptions,
    noticeEnum,
  };
});
